package com.zhdl.modules.demo.task;

import cn.hutool.json.JSONUtil;
import com.zhdl.modules.autopick.ProcessControl;
import com.zhdl.modules.autopick.ProcessControlSignal;
import com.zhdl.websocket.service.WebSocketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import static com.zhdl.network.servertcp.ModBusTcpServerHandler.ipMaps;


/**
 * @Author: zhangyy
 * @Email: zhang10092009@hotmail.com
 * @Date: 2023/7/13 15:18:56
 * @Version: v1.0
 * @Modified:
 * @Description:
 */
@Slf4j
@Component
public class TaskDemoTest {

    @Autowired
    private WebSocketService webSocketService;

    @Autowired
    private ProcessControl processControl;

    @Autowired
    private ProcessControlSignal processControlSignal;

    @Scheduled(fixedRate = 2000, initialDelay = 30 * 1000)
    public void task1() {
        //log.debug("启动后30秒运行一次，以后每隔两秒运行一次");
    }

    @Scheduled(fixedRate = 1000)
    public void task() {
//        String jsonStr = JSONUtil.toJsonStr(processControl.sseResp);
//        String jsonStr1 = JSONUtil.toJsonStr(processControlSignal.sseResp);
        String jsonStr = JSONUtil.toJsonStr(ipMaps);
//        webSocketService.sendMessage(jsonStr);
//        webSocketService.sendMessage(jsonStr);
//        log.info(jsonStr);
    }

    @Scheduled(cron = "0 5 0 * * ?")
    public void test2() {
        //log.info("每天凌晨 0 点 5 分执行任务的表达式");
    }

    @Scheduled(cron = "0 18 10-16 * * ?")
    public void test3() {
        log.info("每天 10 点到 16 点的 18 分定点执行生效的表达式");
    }
}
